package com.zrrd.map;

import java.util.HashMap;
import java.util.Set;

/**
 * @author WanJl
 * @version 1.0
 * @title HashMapTest01
 * @description
 * @create 2024/4/21
 */
public class HashMapTest01 {
    public static void main(String[] args) {
        //创建HashMap对象
        HashMap<Student,String> hashMap = new HashMap();
        
        //创建学生对象
        Student s1 = new Student("张一", 66);
        Student s2 = new Student("张二", 35);
        Student s3 = new Student("钱三", 25);
        Student s4 = new Student("丁四", 25);
        Student s5 = new Student("李五", 95);
        Student s6 = new Student("王六", 15);

        //把学生对象作为key，字符串作为value，添加进集合
        hashMap.put(s1,"哈尔滨");
        hashMap.put(s2,"佳木斯");
        hashMap.put(s3,"北京");
        hashMap.put(s4,"上海");
        hashMap.put(s5,"广州");
        hashMap.put(s6,"齐齐哈尔滨");

        //遍历集合
        Set<Student> students = hashMap.keySet();
        for(Student key : students){
            String value = hashMap.get(key);
            System.out.println(key+":"+value);
        }
    }
}
